<template>
    <view>
        <!-- pages/question_detail/question_detail.wxml -->

        <view class="detail" v-if="datalist.length > 0">
            <view class="content">
                <view class="userInfo">
                    <image class="autherAvatar" :src="userAvatar + datalist[0].authorid"></image>

                    <view class="auther_info">
                        <view class="auther fontWeight">
                            <view class="username">
                                {{ datalist[0].nickname ? datalist[0].nickname : datalist[0].author }}
                            </view>
                        </view>
                        <rich-text class="time" :nodes="datalist[0].dateline"></rich-text>
                    </view>
                    <view class="classType" v-if="thread.typename">
                        <image class="classimage" :src="minImgDoc + 'class_type.png'"></image>
                        <view class="c_type">{{ thread.typename }}</view>
                    </view>
                </view>

                <block v-if="special_poll">
                    <view class="grayRow">
                        {{ !isExpirations ? '投票进行中' : '投票已结束' }}，已有{{ special_poll.voterscount }}人参加
                        <text class="lookjoin" @tap="lookjoin" v-if="datalist[0].authorid == member_uid || special_poll.overt == 1">查看参与投票的人</text>
                    </view>
                </block>

                <view class="worker">
                    <view class="easyTitle">
                        {{ thread.subject }}
                        <text class="choice-tip" v-if="special_poll">（{{ special_poll.maxchoices > 1 ? '多选' : '单选' }}）</text>
                    </view>
                    <rich-text class="message easyMessage" :nodes="datalist[0].message"></rich-text>

                    <!-- 投票开始 -->
                    <view class="poll-list">
                        <block v-if="special_poll.maxchoices > 1">
                            <checkbox-group @change="checkboxChange">
                                <block v-for="(item, index) in special_poll.polloptions" :key="item.polloptionid">
                                    <view class="poll-cell">
                                        <image class="vote-image" :src="baseUrl + '/' + item.imginfo.small" mode="widthFix" v-if="item.imginfo.length != 0"></image>

                                        <label class="checkbox">
                                            <checkbox :value="item.polloptionid" name="visibilitypoll" />
                                            {{ item.polloption }}
                                            <view class="poll-bar-c" v-if="(special_poll.allowvote != 1 && special_poll.visiblepoll == 1) || datalist[0].authorid == member_uid">
                                                <view :class="'poll-bar-p ' + (item.percent < 50 ? 'poll-p-little' : '')" :style="'width:' + item.width"></view>
                                                <text :class="'poll-number ' + (item.percent < 50 ? 'poll-t-little' : '')">{{ item.percent }}%({{ item.votes }})</text>
                                            </view>
                                        </label>
                                    </view>
                                </block>
                            </checkbox-group>
                        </block>
                        <block v-else>
                            <radio-group @change="radioChange">
                                <block v-for="(item, index) in special_poll.polloptions" :key="item.polloptionid">
                                    <view class="poll-cell">
                                        <image :src="baseUrl + '/' + item.imginfo.small" v-if="item.imginfo.length != 0" class="vote-image" mode="widthFix"></image>

                                        <label class="checkbox">
                                            <radio :value="item.polloptionid" name="visibilitypoll" />
                                            {{ item.polloption }}
                                            <view class="poll-bar-c" v-if="(special_poll.allowvote != 1 && special_poll.visiblepoll == 1) || datalist[0].authorid == member_uid">
                                                <view :class="'poll-bar-p ' + (item.percent < 50 ? 'poll-p-little' : '')" :style="'width:' + item.width"></view>
                                                <text :class="'poll-number ' + (item.percent < 50 ? 'poll-t-little' : '')">{{ item.percent }}%({{ item.votes }})</text>
                                            </view>
                                        </label>
                                    </view>
                                </block>
                            </radio-group>
                        </block>
                    </view>
                    <view class="is-vote-tip" v-if="special_poll && special_poll.allowvote != 1 && !isExpirations">您已投过票，谢谢您的参与</view>
                    <!-- 投票end -->

                    <button class="weui-btn poll-btn" type="primary" @tap="submitPoll" v-if="special_poll.allowvote == 1 && !isExpirations">提交</button>

                    <view class="attachlist" v-if="datalist[0].attachments">
                        <block v-for="(image, index) in datalist[0].imageA" :key="image.aid">
                            <image class="attachImage" :src="image.newUrl" mode="widthFix" :id="index" data-cellindex="0" @tap.stop.prevent="lookImage"></image>
                        </block>
                        <block v-for="(video, index) in datalist[0].videoA" :key="video.aid">
                            <view class="viodeoView">
                                <video
                                    id="myVideo"
                                    class="uploader__video uploader__input"
                                    :controls="false"
                                    :show-fullscreen-btn="false"
                                    @play="playVideo"
                                    @fullscreenchange="fullScreenChange"
                                    :src="video.newUrl"
                                ></video>
                            </view>
                        </block>
                    </view>
                    <block v-for="(audio, index) in datalist[0].audioA" :key="audio.aid">
                        <!-- parse <template is="audio_player" :data="...audio.toolUse,minImgDoc"/> -->
                        <block name="audio_player">
                            <view class="audio-playView">
                                <image
                                    :src="is_play && currentAudio == attachment ? minImgDoc + 'audio_play.png' : minImgDoc + 'audio_paused.png'"
                                    class="audio-icon audio-play"
                                    :data-listindex="listIndex"
                                    @tap.stop.prevent="audio_play"
                                    :id="attachment"
                                ></image>
                                <view class="control-process">
                                    <text class="current-process">
                                        <block v-if="current_process.length > 0 && currentAudio == attachment">
                                            {{ current_process }}
                                        </block>
                                        <block v-else>00:00</block>
                                    </text>

                                    <text class="total-process">
                                        <block>
                                            {{ total_process }}
                                        </block>
                                    </text>
                                    <slider
                                        class="slider"
                                        @change="hanle_slider_change"
                                        @touchstart="handle_slider_move_start"
                                        @touchend="handle_slider_move_end"
                                        min="0"
                                        block-size="12"
                                        block-color="#6199fd"
                                        :max="slider_max"
                                        activeColor="#5abf39"
                                        backgroundColor="rgb(153,153,153,0.4)"
                                        :value="currentAudio == attachment ? slider_value : 0"
                                    />
                                </view>
                            </view>
                        </block>
                    </block>
                </view>

                <view class="sharecollect">
                    <view class="share">
                        <button open-type="share" :plain="true" @tap="share">
                            <image class="shareIcon1" :src="minImgDoc + 'share_work.png'" mode="widthFix"></image>
                        </button>
                        <view>分享</view>
                    </view>
                    <view class="share">
                        <image class="collectIcon" :src="minImgDoc + 'collect_work.png'" mode="widthFix" @tap.stop.prevent="collectThread"></image>
                        <view>{{ collecttext }}</view>
                    </view>
                </view>
            </view>

            <view class="grayRow replyInfo">
                <view></view>
                <view class="sortTip" @tap="showSort">{{ listSortType }}</view>

                <view class="shortListContain" v-if="sortListShow">
                    <image :src="minImgDoc + 'sortList.png'" mode="top" class="shortList"></image>
                    <view class="sortType sortTypeF" @tap.stop.prevent="sortClick" id="2">
                        <view>默认顺序</view>
                        <image class="sortCheck" :src="minImgDoc + 'check.png'" v-if="sortdefault"></image>
                    </view>
                    <view class="sortType" id="1" @tap.stop.prevent="sortClick">
                        <view>按时间</view>
                        <image class="sortCheck" :src="minImgDoc + 'check.png'" v-if="!sortdefault"></image>
                    </view>
                </view>
            </view>

            <view class="reply">
                <block v-for="(item, index) in datalist" :key="item.pid">
                    <view class="replyCell" :id="item.pid" v-if="index != 0" @tap="cellClick">
                        <view class="replyerInfo">
                            <image class="avatar" :src="userAvatar + item.authorid"></image>
                            <view class="auther_info">
                                <view class="username fontWeight">
                                    {{ item.nickname ? item.nickname : item.username }}
                                </view>
                                <rich-text class="retime" :nodes="item.dateline"></rich-text>
                            </view>
                        </view>

                        <view class="messageView">
                            <rich-text class="message" :nodes="item.message"></rich-text>
                            <view class="attachlist" v-if="item.attachments">
                                <view :class="'attachementView ' + (item.imageA.length == 0 && item.videoA.length == 1 ? 'singleVideo' : '')" v-if="item.attachments">
                                    <block v-for="(attItem, imgIndex) in item.imageA" :key="attItem.aid">
                                        <image
                                            :class="'attachement ' + (item.imageA.length == 1 && item.videoA.length == 0 ? 'signle-image' : '')"
                                            :mode="item.imageA.length + item.videoA.length == 1 ? 'widthFix' : 'aspectFill'"
                                            :src="attItem.newUrl"
                                            :id="imgIndex"
                                            :data-cellindex="index"
                                            @tap.stop.prevent="lookImage"
                                        ></image>
                                    </block>

                                    <block v-for="(video, aidx) in item.videoA" :key="video.aid">
                                        <image @tap.stop.prevent="clickVideo" :id="video.newUrl" class="attachement" :src="minImgDoc + 'videoPlace.png'"></image>
                                    </block>
                                </view>
                                <block v-for="(audio, index1) in item.audioA" :key="attItem.aid">
                                    <!-- parse <template is="audio_player" :data="...audio.toolUse,minImgDoc"/> -->
                                    <block name="audio_player">
                                        <view class="audio-playView">
                                            <image
                                                :src="is_play && currentAudio == attachment ? minImgDoc + 'audio_play.png' : minImgDoc + 'audio_paused.png'"
                                                class="audio-icon audio-play"
                                                :data-listindex="listIndex"
                                                @tap.stop.prevent="audio_play"
                                                :id="attachment"
                                            ></image>
                                            <view class="control-process">
                                                <text class="current-process">
                                                    <block v-if="current_process.length > 0 && currentAudio == attachment">
                                                        {{ current_process }}
                                                    </block>
                                                    <block v-else>00:00</block>
                                                </text>

                                                <text class="total-process">
                                                    <block>
                                                        {{ total_process }}
                                                    </block>
                                                </text>
                                                <slider
                                                    class="slider"
                                                    @change="hanle_slider_change"
                                                    @touchstart="handle_slider_move_start"
                                                    @touchend="handle_slider_move_end"
                                                    min="0"
                                                    block-size="12"
                                                    block-color="#6199fd"
                                                    :max="slider_max"
                                                    activeColor="#5abf39"
                                                    backgroundColor="rgb(153,153,153,0.4)"
                                                    :value="currentAudio == attachment ? slider_value : 0"
                                                />
                                            </view>
                                        </view>
                                    </block>
                                </block>
                            </view>
                        </view>

                        <view class="flowerAndDiscuss">
                            <!-- <image hidden='true' src="{{item.issupport==1?minImgDoc+'work_flowered.png':minImgDoc+'work_flower.png'}}" class='workButton' catchtap='sendFlower' id="{{index}}"></image> -->
                            <view class="support" @tap.stop.prevent="sendFlower" :id="index">
                                <image src="/static/image/support.png"></image>
                                <view class="support-count">{{ item.postreview ? item.postreview.support : 0 }}</view>
                            </view>
                            <image :src="minImgDoc + 'work_discuss.png'" class="workButton" @tap.stop.prevent="replyWork" :id="item.pid"></image>
                        </view>

                        <view class="workReply" v-if="item.comments">
                            <block v-for="(wreply, index1) in item.comments" :key="wreply.id">
                                <view class="workReplyText">
                                    <text class="workReplyAuthor">{{ wreply.nickname ? wreply.nickname : wreply.author }}：</text>
                                    {{ wreply.comment }}
                                </view>
                            </block>
                            <view
                                @tap="commentMore"
                                class="commentMore"
                                :data-index="index"
                                :data-pid="item.pid"
                                v-if="commentMoreLock[item.pid] !== false && datalist[index].comments.length >= 5"
                            >
                                查看更多>
                            </view>
                        </view>
                    </view>
                </block>
            </view>
            <view class="noMoreView" v-if="!hasMore">别再用力了，你已经滑到底啦</view>
        </view>
        <video id="detailVideo" :autoplay="true" @play="playVideo" @fullscreenchange="fullScreenChange" :src="currentVideo"></video>

        <!-- 底部栏 -->
        <view class="toolbar">
            <view class="input-area" @tap.stop.prevent="replyText">请输入内容</view>
            <button open-type="share" :plain="true" @tap="share">
                <image class="shareIcon" :src="minImgDoc + 'course_share.png'"></image>
                <text class="shareText">分享</text>
            </button>
        </view>
    </view>
</template>

<script>
// pages/question_detail/question_detail.js
const detailUrl = require('../../config').detailUrl;

const baseUrl = require('../../config').baseUrl;

const pollvoteUrl = require('../../config').pollvoteUrl;

const collectUrl = require('../../config').collectUrl;

const sendFlowerUrl = require('../../config').sendFlowerUrl;

const joinClassUrl = require('../../config').joinClassUrl;

const util = require('../../utils/util.js');

const commentMoreUrl = require('../../config').commentMoreUrl;

const minImgDoc = require('../../config').minImgDoc;

const userAvatar = require('../../config').userAvatar;

const loginmanager = require('../../utils/loginManager');

const duration = 2000;
const app = getApp();

export default {
    data() {
        return {
            userAvatar: userAvatar,
            minImgDoc: minImgDoc,
            baseUrl: baseUrl,
            nickname: '',
            datalist: [],

            thread: {
                typename: ''
            },

            tid: '',
            fid: '',
            loading: false,
            pagenum: 1,
            ppp: 10,
            favoriteinfo: '',
            collecttext: '收藏',
            favid: 0,
            sortdefault: false,
            listSortType: '按时间',
            sortListShow: false,
            workinfo: null,
            isShare: false,
            isJoin: false,
            pollanswers: [],
            isExpirations: false,
            commentMoreLock: {},
            shareHidden: false,
            hasMore: false,

            special_poll: {
                overt: 0,
                maxchoices: 0,
                polloptions: [],
                allowvote: 0,
                visiblepoll: 0
            },

            member_uid: '',
            currentVideo: '',
            is_moving_slider: false,
            currentAudio: '',

            image: {
                aid: '',
                newUrl: ''
            },

            video: {
                aid: '',
                newUrl: ''
            },

            audio: {
                aid: ''
            },

            is_play: '',
            attachment: '',
            listIndex: [],
            current_process: [],
            total_process: '',
            slider_max: '',
            slider_value: '',

            attItem: {
                aid: '',
                newUrl: ''
            },

            imgIndex: 0,

            wreply: {
                id: '',
                nickname: false,
                author: ''
            }
        };
    },
    onShow: function () {
        this.commentMoreLock= {};
    },
    onReady() {
        this.videoContext = uni.createVideoContext('detailVideo');
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        var tid = options.tid;
        this.tid= tid;this.pagenum= 1;

        if (options.type == 'share') {
            this.isShare = true;
        }

        uni.showLoading();
        this.refreshRequest();
        this.setupAudioPlayer();
    },
    /**
     * 分享
     */
    onShareAppMessage: function (res) {
        this.shareHidden= true;
        var title = this.thread.subject ? this.thread.subject : this.nickname + '邀请你参与问卷调查，快快加入讨论吧';
        var imagePath = minImgDoc + '/static/pages/questionnaire_detail/kehoushare.png';

        if (this.datalist[0].imageA.length > 0) {
            imagePath = this.datalist[0].imageA[0].newUrl;
        }

        var path = '/pages/discovery/discovery?shareid=' + this.tid + '&special=' + this.thread.special;
        return {
            title: title,
            path: path,
            imageUrl: imagePath
        };
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        this.innerAudioContext.destroy();
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.refreshRequest();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if (this.hasMore) {
            this.requestMore(true);
        }
    },
    methods: {
        commentMore(e) {
            var pid = e.currentTarget.dataset.pid;
            var page = this.commentMoreLock[pid];
            var index = e.currentTarget.dataset.index;

            if (typeof page == 'undefined') {
                page = 2;
            }

            var data = {
                pid: pid,
                tid: this.tid,
                page: page
            };
            app.globalData.apimanager
                .getRequest(commentMoreUrl, data)
                .then((res) => {
                    var comments = res.Variables.comments[pid];
                    var usernicknames = res.Variables.usernicknames;

                    if (comments.length > 0) {
                        page++;
                        this.commentMoreLock[pid] = page;

                        for (let key in comments) {
                            let item = comments[key];

                            if (usernicknames) {
                                item.nickname = usernicknames[item.authorid];
                            }
                        }

                        this.datalist[index].comments = this.datalist[index].comments.concat(comments);
                        this.commentMoreLock= this.commentMoreLock;this.datalist= this.datalist;
                    } else {
                        this.commentMoreLock[pid] = false;
                        this.commentMoreLock= this.commentMoreLock;
                    }
                })
                .catch((res) => {
                    console.log(res);
                    uni.showToast({
                        title: '出错了！',
                        icon: 'none'
                    });
                });
        },

        makeRequest() {
            this.loading= true;
            let ordertype = 1;

            if (this.sortdefault) {
                this.listSortType= '默认顺序';
                ordertype = 2;
            }

            let getDic = {
                tid: this.tid,
                page: this.pagenum,
                ppp: this.ppp,
                ordertype: ordertype
            };
            app.globalData.apimanager
                .getRequest(detailUrl, getDic)
                .then((res) => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    let threads = res.Variables.thread;
                    this.fid = threads.fid;
                    let nickname = res.Variables.member_nickname ? res.Variables.member_nickname : res.Variables.member_username;
                    this.nickname= nickname;

                    if (res.Message) {
                        let messageval = res.Message.messageval;

                        if (
                            messageval.indexOf('nonexistence') != -1 ||
                            messageval.indexOf('nopermission') != -1 ||
                            messageval.indexOf('beoverdue') != -1 ||
                            messageval.indexOf('nomedal') != -1
                        ) {
                            uni.showModal({
                                title: '提示',
                                content: res.Message.messagestr,
                                showCancel: false,
                                confirmText: '知道了',
                                success: function (res) {
                                    if (res.confirm) {
                                        uni.navigateBack();
                                    }
                                }
                            });
                            return;
                        }
                    }

                    if (threads.favoriteinfo && threads.favoriteinfo != '') {
                        console.log(threads.favoriteinfo);
                        this.favoriteinfo= threads.favoriteinfo;this.favid= threads.favoriteinfo.favid;
                        this.resetCollectState();
                    }

                    var usernicknames = res.Variables.usernicknames;
                    let arr1 = this.datalist;
                    let listArray = res.Variables.postlist;

                    for (let i = 0; i < listArray.length; i++) {
                        let postItem = listArray[i];

                        if (usernicknames) {
                            if (usernicknames[postItem.authorid]) {
                                postItem.nickname = usernicknames[postItem.authorid];
                            }
                        }

                        postItem.message = postItem.message.replace(/\<img/gi, '<img class="rich-img"');
                        postItem.message = postItem.message.replace(/<font (.*?)>/gi, '');
                        postItem.message = postItem.message.replace(/<\/font>/gi, ''); // 作业评论处理

                        let comments = res.Variables.comments;

                        if (comments && comments.length != 0) {
                            if (comments[postItem.pid]) {
                                let comment = comments[postItem.pid];

                                for (let key in comment) {
                                    let item = comment[key];

                                    if (usernicknames) {
                                        item.nickname = usernicknames[item.authorid];
                                    }
                                }

                                postItem.comments = comment;
                            }
                        }

                        var listindex = i + this.datalist.length; // 附件处理

                        let attachments = postItem.attachments;
                        let imageA = [];
                        let audioA = [];
                        let videoA = [];

                        for (let aidKey in attachments) {
                            let attItem = attachments[aidKey];
                            let newUrl = baseUrl + '/' + attItem.url + attItem.attachment;
                            attItem['newUrl'] = newUrl;

                            if (attItem.isimage != 0) {
                                imageA.push(attItem);
                            } else {
                                if (attItem.ext == 'mp3') {
                                    let total_process = '00:00';

                                    if (attItem.description) {
                                        total_process = util.formatTime(parseInt(attItem.description));
                                    }

                                    attItem['toolUse'] = {
                                        attachment: newUrl,
                                        listIndex: listindex,
                                        total_process: total_process
                                    };
                                    audioA.push(attItem);
                                } else {
                                    if (attItem.ext == 'mp4') {
                                        videoA.push(attItem);
                                    }
                                }
                            }
                        }

                        postItem['imageA'] = imageA;
                        postItem['audioA'] = audioA;
                        postItem['videoA'] = videoA;
                    }

                    if (this.pagenum > 1) {
                        arr1 = arr1.concat(listArray);
                    } else {
                        arr1 = listArray;
                    }

                    if (arr1.length - 1 >= threads.replies) {
                        this.hasMore= false;
                    } else {
                        this.hasMore= true;
                    }

                    if (res.Variables.special_poll) {
                        var timestamp = Date.parse(new Date());
                        timestamp = timestamp / 1000;

                        if (timestamp > res.Variables.special_poll.expirations) {
                            this.isExpirations= true;
                        }

                        this.special_poll= res.Variables.special_poll;
                    }

                    this.setData({
                        loading: false,
                        datalist: arr1,
                        thread: threads,
                        member_uid: res.Variables.member_uid
                    });
                })
                .catch((res) => {
                    uni.stopPullDownRefresh();
                    uni.hideLoading();
                    this.loading= false;
                    uni.showToast({
                        title: '出错了！',
                        icon: 'none'
                    });
                });
        },

        showSort() {
            this.sortListShow= !this.sortListShow;
        },

        sortClick(e) {
            let id = e.currentTarget.id;
            let sortdefault = true;
            let listSortType = '默认顺序';

            if (id == 1) {
                sortdefault = false;
                listSortType = '按时间';
            }

            this.pagenum = 1;
            this.setData({
                sortdefault: sortdefault,
                listSortType: listSortType,
                sortListShow: false
            });
            this.makeRequest();
        },

        resetCollectState() {
            let collecttext = this.collecttext;

            if (this.favid != 0) {
                collecttext = '已收藏';
            } else {
                collecttext = '收藏';
            }

            console.log(collecttext);
            this.collecttext= collecttext;
        },

        collectThread() {
            if (this.favid != 0) {
                // 已收藏 取消收藏
                let url = collectUrl + '&op=delete&deletesubmit=yes';
                let formhash = app.globalData.formhash;
                let postData = {
                    formhash: formhash,
                    favid: this.favid
                };
                app.globalData.apimanager
                    .postRequest(url, postData)
                    .then((res) => {
                        if (res.Message.messageval == 'do_success') {
                            this.favoriteinfo= '';this.favid= 0;
                            this.resetCollectState();
                        } else {
                            uni.showToast({
                                title: res.Message.messagestr,
                                icon: 'none'
                            });
                        }
                    })
                    .catch((res) => {
                        uni.showToast({
                            title: '出错了！',
                            icon: 'none'
                        });
                    });
            } else {
                // 未收藏 去收藏
                let formhash = app.globalData.formhash;
                let data = {
                    formhash: formhash,
                    id: this.tid
                };
                app.globalData.apimanager
                    .getRequest(collectUrl, data)
                    .then((res) => {
                        if (res.Message.messageval == 'favorite_do_success') {
                            this.favid= res.Variables.favid;
                            this.resetCollectState();
                        } else {
                            uni.showToast({
                                title: res.Message.messagestr,
                                icon: 'none'
                            });
                        }
                    })
                    .catch((res) => {
                        uni.showToast({
                            title: '出错了！',
                            icon: 'none'
                        });
                    });
            }
        },

        toReply() {
            uni.navigateTo({
                url: '../post_thread/post_thread?isreply=true'
            });
        },

        replyText() {
            if (!loginmanager.isLogin()) {
                return;
            }

            uni.navigateTo({
                url: '../post_thread/post_thread?isreply=true&type=text'
            });
        },

        replyAudio() {
            uni.navigateTo({
                url: '../post_thread/post_thread?isreply=true&type=audio'
            });
        },

        replyImage() {
            uni.navigateTo({
                url: '../post_thread/post_thread?isreply=true&type=image'
            });
        },

        replyVideo() {
            uni.navigateTo({
                url: '../post_thread/post_thread?isreply=true&type=video'
            });
        },

        replyWork(e) {
            if (!loginmanager.isLogin()) {
                return;
            }

            uni.navigateTo({
                url: '../post_thread/post_thread?isevaluate=true&pid=' + e.currentTarget.id
            });
        },

        sendFlower(e) {
            let index = parseInt(e.currentTarget.id);
            let replyItem = this.datalist[index];
            let formhash = app.globalData.formhash;
            let data = {
                tid: this.tid,
                pid: replyItem.pid,
                hash: formhash
            };
            app.globalData.apimanager
                .getRequest(sendFlowerUrl, data)
                .then((res) => {
                    if (res.Message.messageval == 'thread_poll_succeed') {
                        if (replyItem.postreview && replyItem.postreview.support) {
                            replyItem.postreview.support = parseInt(replyItem.postreview.support) + 1;
                        } else {
                            var postreview = {
                                support: 1
                            };
                            replyItem['postreview'] = postreview;
                        }

                        let param = {};
                        let str = 'datalist[' + index + ']';
                        param[str] = replyItem;
                        this.setData(param);
                    } else {
                        uni.showToast({
                            title: res.Message.messagestr,
                            icon: 'none'
                        });
                    }
                })
                .catch((res) => {
                    uni.showToast({
                        title: '出错了',
                        icon: 'none'
                    });
                });
        },

        // 播放视频 -------------------
        clickVideo(e) {
            this.currentVideo= e.currentTarget.id;
            this.videoContext.requestFullScreen({
                direction: 0
            });
        },

        fullScreenChange(e) {
            if (!e.detail.fullScreen) {
                this.videoContext.stop();
            }
        },

        /* *********************** 语音相关start *********** */
        setupAudioPlayer() {
            this.innerAudioContext = uni.createInnerAudioContext();
            this.innerAudioContext.obeyMuteSwitch = false;
            this.innerAudioContext.onEnded((res) => {
                this.currentAudio.toolUse.is_ended = true;
                this.stopVoice();
            });
            this.innerAudioContext.onTimeUpdate(() => {
                if (!this.is_moving_slider) {
                    // 播放中
                    this.currentAudio = this.datalist[this.currentAudio.toolUse.listIndex].audioA[0];
                    let param = {};
                    let toolUsestr = 'datalist[' + this.currentAudio.toolUse.listIndex + '].audioA[0].toolUse';
                    let toolUse = this.currentAudio.toolUse;
                    toolUse['current_process'] = util.formatTime(this.innerAudioContext.currentTime);
                    toolUse['slider_value'] = Math.floor(this.innerAudioContext.currentTime);
                    toolUse['slider_max'] = Math.floor(this.innerAudioContext.duration);
                    param[toolUsestr] = toolUse;
                    this.setData(param);
                }
            });
        },

        // 拖动进度条，到指定位置
        hanle_slider_change(e) {
            const position = e.detail.value;
            this.seekCurrentAudio(position);
        },

        // 拖动进度条控件
        seekCurrentAudio(position) {
            this.innerAudioContext.seek(position);
        },

        // 进度条滑动
        handle_slider_move_start() {
            this.is_moving_slider= true;
        },

        handle_slider_move_end() {
            this.is_moving_slider= false;
        },

        // 点击播放暂停
        audio_play(e) {
            let listIndex = e.currentTarget.dataset.listindex;
            let postItem = this.datalist[listIndex];
            let currentAudio = postItem.audioA[0];
            var param = {};
            let audioset = 'datalist[' + listIndex + '].audioA[0].toolUse.currentAudio';
            param[audioset] = currentAudio.newUrl;
            this.setData(param);
            this.currentAudio= currentAudio;
            let isplay = this.currentAudio.toolUse.is_play;
            let playstr = 'datalist[' + listIndex + '].audioA[0].toolUse.is_play';
            param[playstr] = !isplay;
            this.setData(param);

            if (isplay) {
                this.innerAudioContext.pause();
                isplay = false;
            } else {
                if (!isplay && !this.currentAudio.toolUse.is_ended) {
                    this.playVoice();
                } else {
                    this.innerAudioContext.play();
                }
            }
        },

        playVoice() {
            var src = this.currentAudio.newUrl;
            this.innerAudioContext.src = src;
            this.innerAudioContext.play();
        },

        stopVoice() {
            var param = {};
            let toolUsestr = 'datalist[' + this.currentAudio.toolUse.listIndex + '].audioA[0].toolUse';
            let toolUse = this.currentAudio.toolUse;
            toolUse['is_play'] = false;
            toolUse['slider_value'] = 0;
            toolUse['current_process'] = util.formatTime(0);
            param[toolUsestr] = toolUse;
            this.setData(param);
            this.innerAudioContext.stop();
            this.currentAudio = this.datalist[this.currentAudio.toolUse.listIndex].audioA[0];
        },

        /* *********************** 语音end *********** */
        lookImage(e) {
            let cellItem = this.datalist[e.currentTarget.dataset.cellindex];
            let imageA = cellItem.imageA;
            var imageSrcArray = [];

            for (let i = 0; i < imageA.length; i++) {
                let item = imageA[i];
                imageSrcArray.push(item.newUrl);
            }

            console.log(imageSrcArray);
            uni.previewImage({
                current: imageSrcArray[e.currentTarget.id],
                urls: imageSrcArray
            });
        },

        requestMore(isMore) {
            let pagenum = this.pagenum;

            if (isMore) {
                pagenum += 1;
            } else {
                pagenum = 1;
            }

            this.pagenum= pagenum // 更新当前页数;
            this.makeRequest(); // 重新调用请求获取下一页数据 或者刷新数据
        },

        radioChange(e) {
            var pollanswers = [];
            pollanswers[0] = e.detail.value;
            this.pollanswers= pollanswers;
        },

        checkboxChange(e) {
            this.pollanswers= e.detail.value;
        },

        refreshRequest() {
            this.requestMore(false);
        },

        submitPoll() {
            var urlStr = pollvoteUrl + '&fid=' + this.fid + '&tid=' + this.tid;
            var postData = {
                formhash: app.globalData.formhash
            };

            for (let i = 0; i < this.pollanswers.length; i++) {
                var keyStr = 'pollanswers[' + i + ']';
                postData[keyStr] = this.pollanswers[i];
            }

            app.globalData.apimanager
                .postRequest(urlStr, postData)
                .then((res) => {
                    if (res.Message.messageval.indexOf('succeed') != -1) {
                        uni.showToast({
                            title: '投票成功'
                        });
                        this.refreshRequest();
                    }
                })
                .catch((res) => {});
        },

        lookjoin() {
            uni.navigateTo({
                url: '../vote_list/vote_list?tid=' + this.tid
            });
        },

        playVideo() {
            console.log('占位：函数 playVideo 未声明');
        },

        share() {
            console.log('占位：函数 share 未声明');
        },

        cellClick() {
            console.log('占位：函数 cellClick 未声明');
        }
    }
};
</script>
<style>
@import './questionnaire_detail.css';
</style>
